import pyodbc


class DataBase:
    @staticmethod
    def db_open(filename):
        file = filename
        print("file name = ", file)
        conn = pyodbc.connect(r"Driver={Driver do Microsoft Access (*.mdb)};DBQ=" + file + ";Uid=;Pwd=;")
        curse = conn.cursor()
        return conn, curse

    @staticmethod
    def db_command(conn, curse, cmd):
        if (curse is None) or (conn is None) or (cmd == ""):
            print("input para error")
            return None
        data_list = list(curse.execute(cmd))
        print("count = ", data_list.__len__())
        return data_list

    @staticmethod
    def db_close(conn, curse):
        conn.close()
        curse.close()


if __name__ == '__main__':
    conn, curse = DataBase.dbopen("D:\EmbededDebug v2.0\data.mdb")
    DataBase.dbcommand(conn,curse, "SELECT * from EDtxRecord")
